package org.dreamfly.dreamalarm;

import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardLock;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;

import com.github.droidfu.activities.BetterDefaultActivity;
import com.umeng.analytics.MobclickAgent;

/**
 * 在系统处于睡眠状态点亮屏幕
 * 
 * @author Jason_wbw
 */

public class LightScreenAndUnlockActivity extends BetterDefaultActivity {

	// 声明键盘管理器
	KeyguardManager mKeyguardManager = null;  
	//声明键盘锁
	private KeyguardLock mKeyguardLock = null;  
	//声明电源管理器
	private PowerManager pm;
	private PowerManager.WakeLock wakeLock;
 
	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		//获取电源的服务
	    pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
	    //获取系统服务
	    mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
	    super.onCreate(savedInstanceState); 
	    
	    //点亮亮屏
		wakeLock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.SCREEN_DIM_WAKE_LOCK, "My Tag");
		wakeLock.acquire();
		Log.i("Log : ", "------>mKeyguardLock");
		//初始化键盘锁，可以锁定或解开键盘锁
		mKeyguardLock = mKeyguardManager.newKeyguardLock("");  
		//禁用显示键盘锁定
		mKeyguardLock.disableKeyguard();  
	}  
	
	@Override
	protected void onDestroy() {
		wakeLock.release();
		super.onDestroy();
	}  
	
	@Override
	protected void onResume() {
	    super.onResume();
	    MobclickAgent.onResume(this);
	}
	@Override
	protected void onPause() {
	    super.onPause();
	    MobclickAgent.onPause(this);
	}
	
}
